package com.lianbang.pharmacy.adapter

import cn.ubest.mvvmcore.utils.ResourcesUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.flyco.roundview.RoundTextView
import com.lianbang.pharmacy.R
import com.lianbang.pharmacy.bean.Sign

/**
 * Created by maoqi on 2020/12/16.
 */
class SignListAdapter(var signDays: Int) :
    BaseQuickAdapter<Sign, BaseViewHolder>(R.layout.item_sign_list) {
    override fun convert(helper: BaseViewHolder, item: Sign) {
        val curSign = helper.layoutPosition + 1 == signDays
        helper.setText(R.id.tv_score, "${item.sign_num}积分")
            .setText(R.id.tv_title, item.day)
            .setText(
                R.id.tv_position,
                if (curSign) "√" else "${helper.layoutPosition + 1}"
            )
            .setVisible(R.id.iv_tag, curSign)
            .setVisible(R.id.tv_cur, curSign)
            .setVisible(R.id.tv_position, !curSign)
        when {
            helper.layoutPosition+ 1 < signDays -> {
                helper.setTextColor(R.id.tv_position, ResourcesUtils.getColor("#ffffff"))
                helper.setTextColor(R.id.tv_cur, ResourcesUtils.getColor("#ffffff"))
                helper.setBackgroundColor(R.id.view_left, ResourcesUtils.getColor("#5671FB"))
                helper.setBackgroundColor(R.id.view_right, ResourcesUtils.getColor("#5671FB"))
                helper.getView<RoundTextView>(R.id.tv_position).delegate.backgroundColor =
                    ResourcesUtils.getColor("#5671FB")
                helper.getView<RoundTextView>(R.id.tv_cur).delegate.backgroundColor =
                    ResourcesUtils.getColor("#5671FB")
            }
            helper.layoutPosition+ 1 == signDays -> {
                helper.setTextColor(R.id.tv_position, ResourcesUtils.getColor("#ffffff"))
                helper.setTextColor(R.id.tv_cur, ResourcesUtils.getColor("#ffffff"))
                helper.setBackgroundColor(R.id.view_left, ResourcesUtils.getColor("#5671FB"))
                helper.setBackgroundColor(R.id.view_right, ResourcesUtils.getColor("#DBE1FF"))
                helper.getView<RoundTextView>(R.id.tv_position).delegate.backgroundColor =
                    ResourcesUtils.getColor("#5671FB")
                helper.getView<RoundTextView>(R.id.tv_cur).delegate.backgroundColor =
                    ResourcesUtils.getColor("#5671FB")
            }
            helper.layoutPosition+ 1 > signDays -> {
                helper.setTextColor(R.id.tv_position, ResourcesUtils.getColor("#5671FB"))
                helper.setTextColor(R.id.tv_cur, ResourcesUtils.getColor("#5671FB"))
                helper.setBackgroundColor(R.id.view_left, ResourcesUtils.getColor("#DBE1FF"))
                helper.setBackgroundColor(R.id.view_right, ResourcesUtils.getColor("#DBE1FF"))
                helper.getView<RoundTextView>(R.id.tv_position).delegate.backgroundColor =
                    ResourcesUtils.getColor("#DBE1FF")
                helper.getView<RoundTextView>(R.id.tv_cur).delegate.backgroundColor =
                    ResourcesUtils.getColor("#DBE1FF")
            }
        }
    }

}